package com.nmsl.sn.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.sn.domain.SnVisitRecord;
import com.nmsl.sn.service.ISnVisitRecordService;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.common.core.page.TableDataInfo;

/**
 * 就诊记录Controller
 * 
 * @author sn
 * @date 2025-02-21
 */
@RestController
@RequestMapping("/sn/record")
public class SnVisitRecordController extends BaseController
{
    @Autowired
    private ISnVisitRecordService snVisitRecordService;

    /**
     * 查询就诊记录列表
     */
    @PreAuthorize("@ss.hasPermi('sn:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(SnVisitRecord snVisitRecord)
    {
        startPage();
        List<SnVisitRecord> list = snVisitRecordService.selectSnVisitRecordList(snVisitRecord);
        return getDataTable(list);
    }

    /**
     * 导出就诊记录列表
     */
    @PreAuthorize("@ss.hasPermi('sn:record:export')")
    @Log(title = "就诊记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SnVisitRecord snVisitRecord)
    {
        List<SnVisitRecord> list = snVisitRecordService.selectSnVisitRecordList(snVisitRecord);
        ExcelUtil<SnVisitRecord> util = new ExcelUtil<SnVisitRecord>(SnVisitRecord.class);
        util.exportExcel(response, list, "就诊记录数据");
    }

    /**
     * 获取就诊记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('sn:record:query')")
    @GetMapping(value = "/{visitRecordId}")
    public AjaxResult getInfo(@PathVariable("visitRecordId") Long visitRecordId)
    {
        return success(snVisitRecordService.selectSnVisitRecordByVisitRecordId(visitRecordId));
    }

    /**
     * 新增就诊记录
     */
    @PreAuthorize("@ss.hasPermi('sn:record:add')")
    @Log(title = "就诊记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SnVisitRecord snVisitRecord)
    {
        // 插入就诊记录
        int result = snVisitRecordService.insertSnVisitRecord(snVisitRecord);
        if (result > 0) {
            // 返回插入后的 visitRecordId
            return AjaxResult.success("新增成功", snVisitRecord.getVisitRecordId());
        } else {
            return AjaxResult.error("新增失败");
        }
    }

    /**
     * 修改就诊记录
     */
    @PreAuthorize("@ss.hasPermi('sn:record:edit')")
    @Log(title = "就诊记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SnVisitRecord snVisitRecord)
    {
        return toAjax(snVisitRecordService.updateSnVisitRecord(snVisitRecord));
    }

    /**
     * 删除就诊记录
     */
    @PreAuthorize("@ss.hasPermi('sn:record:remove')")
    @Log(title = "就诊记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{visitRecordIds}")
    public AjaxResult remove(@PathVariable Long[] visitRecordIds)
    {
        return toAjax(snVisitRecordService.deleteSnVisitRecordByVisitRecordIds(visitRecordIds));
    }
}
